
module Tikhonov (linsolveReg) where

import Numeric.LinearAlgebra
import Data.Packed.Matrix
import Data.Packed.Vector

linsolveReg :: Double -> Matrix Double -> Matrix Double -> Matrix Double
linsolveReg alpha a b = (v * d * (trans u)) * b
        where   (u, s, v) = svd a
                d         = buildMatrix (rows v) (cols u) dBuild
                dBuild (i,j)    | i==j = (s @> i)**2/((s @> i)+alpha)
                                | otherwise = 0.0